package org.harryrose.resultkit.exceptions;

import java.lang.reflect.Field;

/**
 * Thrown when the type of the variable being saved is unsupported (normally when saving a non-numeric type
 * using SaveMean or SaveVariance)
 * @author harry
 *
 */
public class TypeException extends Exception{
	
	Object object;
	Field field;
	
	public TypeException()
	{
		this(null,null);
	}
	
	public TypeException(Object object, Field field, String message)
	{
		super(message);
		this.object = object;
		this.field = field;
	}

	public TypeException(Object object, Field field)
	{
		this(object,field,"Unsupported Type ("+field.getClass().getName()+")");
	}
	
	public TypeException(String message)
	{
		this(null,null,message);
	}
	
	@Override
	public String getMessage()
	{
		String out = "Error";
		if(object != null && field != null)
		{
			out += " in object "+object.getClass()+", field "+field.getName();
		}
		
		out += ": "+getMessage();
		
		return out;
	}
}
